import 'package:flutter/material.dart';
import 'package:note_life/theme.dart';
import 'package:note_life/StaticData.dart';
import 'package:note_life/color.dart';
import 'mainpage_body.dart';
import 'package:flutter/animation.dart';
import 'package:note_life/clod_note_create/cloud_note_create_classify_check.dart';

class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MainPage();
  }
}

class _MainPage extends State<MainPage> with SingleTickerProviderStateMixin {
  Animatable<double> tween;
  AnimationController controller;
  BuildContext mMcontext;

  @override
  void initState() {
    super.initState();
    controller = new AnimationController(
        duration: const Duration(milliseconds: 200),
        animationBehavior: AnimationBehavior.preserve,
        vsync: this);
    tween = Tween(begin: 0.0, end: 1.0)
      ..animate(controller).addListener(() {
        setState(() {});
      });
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    mMcontext = context;
    return Scaffold(
      appBar: AppBar(
        title: Text("首页"),
        centerTitle: true,
        elevation: 0.0,
        actions: <Widget>[Icon(Icons.notifications_none)],
      ),
      drawer: _creatDrawer(context),
      body: MainPageBody(
        callBack: (int type) {
          print("type$type");
          if (type < 0) {
            controller.reverse(from: 1);
          } else if (type > 0) {
            controller.forward(from: 0);
          }
        },
      ),
      floatingActionButton: Container(
        child: FloatingActionButton(
          child: Icon(
            Icons.add,
            color: Colors.white,
            size: controller.value * 22,
          ),
          backgroundColor: AppColor.BLUE_COLOR,
          onPressed: () {
//            Navigator.push(mMcontext,MaterialPageRoute(builder: (context)=>
//              CreateRecordPage()
//            ));
            showModalBottomSheet(
                context: mMcontext,
                builder: (BuildContext context) => Container(
                      color: AppColor.THEME_GB_COLOR,
                      height: 100,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[
                          createBottomMenu(Color(0XFF05668D),
                              Icons.cloud_upload, "云记", () {
                            Navigator.of(context).push(MaterialPageRoute(
                                builder: (context) =>
                                    CloudNoteCreateClassifyCheck()));
                          }),
                          createBottomMenu(
                              Color(0XFF00A896),
                              Icons.account_balance_wallet,
                              "账单",
                              () {}),
                          createBottomMenu(Color(0XFF02C39A), Icons.map, "足迹", () {}),
                          createBottomMenu(Color(0XFFFFE066), Icons.add_a_photo,
                              "相册",  () {})
                        ],
                      ),
                    ));
          },
          mini: true,
        ),
        height: controller.value * 40,
        width: controller.value * 40,
      ),
    );
  }

  Drawer _creatDrawer(BuildContext context) {
    return Drawer(
      child: Scaffold(
          body: Container(
        child: Column(
          children: <Widget>[
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: <Widget>[
                    UserAccountsDrawerHeader(
                      accountName: Text("搬砖的小猪"),
                      accountEmail: Text("243280864@qq.com"),
                      currentAccountPicture: CircleAvatar(
                        backgroundImage: NetworkImage(
                            "http://i10.hoopchina.com.cn/hupuapp/bbs/966/16313966/thread_16313966_20180726164538_s_65949_o_w1024_h1024_62044.jpg?x-oss-process=image/resize,w_800/format,jpg"),
                      ),
                      otherAccountsPictures: <Widget>[
                        Icon(
                          Icons.wb_sunny,
                          color: AppColor.THEME_COLOR,
                        )
                      ],
                    ),
                    createClickItem("云记事本", Icons.content_paste, () {}),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem(
                        "我的记账", Icons.account_balance_wallet, () {}),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem("我的足迹", Icons.location_on, () {}),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem("我的图片", Icons.insert_photo, () {}),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem("夜间模式", Icons.lightbulb_outline, () {
                      if (ThemeUtil.type == ThemeUtil.DARK_THEME) {
                        ThemeUtil.changeTheme(ThemeUtil.BRIGHT_THEME);
                      } else {
                        ThemeUtil.changeTheme(ThemeUtil.DARK_THEME);
                      }
                    }),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem("关于", Icons.info, () {}),
                    Divider(
                      height: 2.0,
                    ),
                    createClickItem("设置", Icons.settings, () {}),
                    Divider(
                      height: 2.0,
                    ),
                  ],
                ),
              ),
              flex: 1,
            ),
            Container(
              padding: EdgeInsets.all(10.0),
              child: Text(
                "power by sun.star",
                style: TextStyle(color: AppColor.THEME_COLOR),
                textAlign: TextAlign.right,
              ),
              alignment: Alignment.bottomRight,
            )
          ],
        ),
      )),
    );
  }

  Widget createClickItem(
      String text, IconData icon, MenuItemCLickCallBack callBack) {
    return InkWell(
      onTap: callBack,
      child: Container(
        child: Row(
          children: <Widget>[
            Icon(
              icon,
              color: AppColor.THEME_COLOR,
            ),
            Container(
              child: Text(
                text,
                style: TextStyle(color: AppColor.THEME_COLOR),
              ),
              margin: EdgeInsets.only(left: 5.0),
            )
          ],
        ),
        padding: EdgeInsets.all(10.0),
      ),
    );
  }

  List<String> heroTagString = new List();

  Widget createBottomMenu(Color colorData, IconData iconData, String s, GestureTapCallback callBack) {
    return Expanded(
      child: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: callBack,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(bottom: 5.0),
              padding: EdgeInsets.all(10.0),
              child: Icon(
                iconData,
                color: Colors.white,
              ),
              decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: colorData,
                  boxShadow: [
                    BoxShadow(
                        blurRadius: 2.0,
                        offset: Offset(3.0, 3.0),
                        color: Colors.black12)
                  ]),
            ),
            Text(
              s,
              style: TextStyle(color: AppColor.THEME_COLOR, fontSize: 14.0),
            )
          ],
        ),
      ),
      flex: 1,
    );
  }
}

typedef MenuItemCLickCallBack();
